home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume7 / nstrings.bsd < prev    next >
Encoding:
Text File  |  1989-06-03  |  54.5 KB  |  1,841 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v07i012: Source of strings, a replacement for the BSD command of the same name.
  4. Reply-To: greim@sbsvax.informatik.uni-saarland.dbp.de (Michael Greim)
  5.  
  6. Posting-number: Volume 7, Issue 12
  7. Submitted-by: greim@sbsvax.informatik.uni-saarland.dbp.de (Michael Greim)
  8. Archive-name: nstrings.bsd
  9.  
  10. [Anyone want to volunteer to convert this for COFF?  ++bsa]
  11.  
  12. Here is strings, a replacement for the BSD program of the same name,
  13. for distribution in comp.sources.misc.
  14.  
  15. I wrote this because I became annoyed by 
  16. - old strings is slow
  17. - old strings is not correct. It thinks ^L and sometimes even 0x80 to be
  18.   printable. (See README for more details)
  19. [Amen to that!  ++bsa]
  20. - old strings has trouble with the segment of initialized data on some
  21.   systems
  22. - on some systems there is strings, on some there isn't
  23.  
  24. It is not only for UNIX systems, but I have only tried it on UNIX and
  25. VMS so far.
  26.  
  27. Absorb, apply and enjoy,
  28.     -mg
  29.  
  30. --
  31. Michael Greim    Email : greim@sbsvax.informatik.uni-saarland.dbp.de
  32.                  or    : ...!uunet!unido!sbsvax!greim
  33.  
  34. #! /bin/sh
  35. # This is a shell archive.  Remove anything before this line, then unpack
  36. # it by saving it into a file and typing "sh file".  To overwrite existing
  37. # files, type "sh file -c".  You can also feed this as standard input via
  38. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  39. # will see the following message at the end:
  40. #        "End of archive 1 (of 1)."
  41. # Contents:  COPYING MANIFEST Makefile README config.h limits.c
  42. #   output.c strings.1 strings.c strings.h strings.txt test_input
  43. #   tune.h
  44. # Wrapped by greim@sbsvax on Tue May 23 18:13:15 1989
  45. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  46. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  47.   echo shar: Will not clobber existing file \"'COPYING'\"
  48. else
  49. echo shar: Extracting \"'COPYING'\" \(1268 characters\)
  50. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  51. X
  52. X    strings
  53. X
  54. X    (C) Copyright by Michael Greim, 5/23/89
  55. X
  56. X-------------------------------------------------------------
  57. X
  58. XThe author, Michael Greim, allows anyone to do anything he/she/it wants with
  59. X"strings", provided the following conditions are met:
  60. X
  61. X- the program may not be sold without the authors written permission
  62. X- this notice stays in place
  63. X- any changes to the original are marked as such
  64. X
  65. X
  66. XThe author explicitly asks anybody :
  67. X
  68. X- to port this program to as much computer systems as possible and send
  69. X  him complaints, results, bug fixes, praise ...
  70. X- to incorporate this program in any package of Public Domain programs for
  71. X  free distribution (GNU would be welcome)
  72. X
  73. X
  74. XThere is no warranty of merchantability nor any warranty of fitness for a
  75. Xparticular purpose nor any other warranty, either express or implied, as
  76. Xto the accuracy of the herewith published program, or as to its
  77. Xsuitability for any particular purpose.
  78. XAccordingly, I, Michael Greim, assume no responsibility
  79. Xfor its use by the recipient. Further, I, Michael Greim, assume no
  80. Xobligation to furnish any assistance of any kind whatsoever,
  81. Xor to furnish any additional information or documentation.
  82. X
  83. X(But if you ask me nice, I might consider to think about starting to
  84. X speculate about it ... :-)
  85. END_OF_FILE
  86. if test 1268 -ne `wc -c <'COPYING'`; then
  87.     echo shar: \"'COPYING'\" unpacked with wrong size!
  88. fi
  89. # end of 'COPYING'
  90. fi
  91. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  92.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  93. else
  94. echo shar: Extracting \"'MANIFEST'\" \(830 characters\)
  95. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  96. X   File Name        Archive #    Description
  97. X-----------------------------------------------------------
  98. X COPYING                    1    Copyright Notice.
  99. X MANIFEST                   1    This shipping list
  100. X Makefile                   1    
  101. X README                     1    What is strings ? How to port it. 
  102. X config.h                   1    Default parameters for different machines.
  103. X limits.c                   1    Get limits of initialized data segment.
  104. X output.c                   1    Output routines.
  105. X strings.1                  1    Manual entry.
  106. X strings.c                  1    Main part of program.
  107. X strings.h                  1    
  108. X strings.txt                1    Manual entry as plain text file.
  109. X test_input                 1    sample (btoa'd) file to demonstrate errors of old "strings".
  110. X tune.h                     1    Parameter settings for current machine.
  111. END_OF_FILE
  112. if test 830 -ne `wc -c <'MANIFEST'`; then
  113.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  114. fi
  115. # end of 'MANIFEST'
  116. fi
  117. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  118.   echo shar: Will not clobber existing file \"'Makefile'\"
  119. else
  120. echo shar: Extracting \"'Makefile'\" \(907 characters\)
  121. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  122. X#
  123. X# Makefile for 'strings'
  124. X#
  125. X# sccsid = @(#)  REL.Mfile  (v1.3 5/22/89)
  126. X#
  127. XSHELL=/bin/sh
  128. X
  129. X# If you want to play it safe, define SAFETY_FIRST. The program will most
  130. X# probably work and you won't have to spend time on porting it.
  131. X# If you have defined things yourself and you want the program
  132. X# to use these definitions, you must define USE_USER_DEFINES.
  133. X# If you don't define SAFETY_FIRST and USE_USER_DEFINES, the program
  134. X# will try to identify your system and then use its defaults.
  135. XUFLAGS=
  136. X#UFLAGS=-DUSE_USER_DEFINES
  137. X#UFLAGS=-DSAFETY_FIRST
  138. X
  139. X# Define DEBUG to get a lot of debug output on "prot".
  140. XDEBUGFLAGS=
  141. X
  142. XCFLAGS= -O ${DEBUGFLAGS} ${UFLAGS}
  143. X
  144. XHEADERS=    strings.h config.h tune.h
  145. XOBJS=        strings.o limits.o output.o
  146. X
  147. Xall: strings
  148. X
  149. Xstrings: ${OBJS}
  150. X    cc -o strings ${OBJS}
  151. X
  152. X${OBJS}:    ${HEADERS}
  153. X
  154. X#strings.o: strings.h config.h tune.h
  155. X#limits.o : strings.h config.h tune.h
  156. X#output.o : strings.h config.h tune.h
  157. END_OF_FILE
  158. if test 907 -ne `wc -c <'Makefile'`; then
  159.     echo shar: \"'Makefile'\" unpacked with wrong size!
  160. fi
  161. # end of 'Makefile'
  162. fi
  163. if test -f 'README' -a "${1}" != "-c" ; then 
  164.   echo shar: Will not clobber existing file \"'README'\"
  165. else
  166. echo shar: Extracting \"'README'\" \(7601 characters\)
  167. sed "s/^X//" >'README' <<'END_OF_FILE'
  168. X1.) What do we have here?
  169. X
  170. XThis is the README file for 'strings'. 'strings' is a rewrite
  171. Xand replacement for the 4BSD program of the same name.
  172. X'strings' looks for sequences of printable characters in a file and
  173. Xoutputs them.
  174. X
  175. XCurrent version is 1.6.9.
  176. X
  177. X(To get best results when reading these files, use an option in your
  178. X favourite editor to expand a TAB to 4 SPACEs. E.g. in vi it is
  179. X "set tabstop=4")
  180. X
  181. XYou should have the files:
  182. X    README        - this file
  183. X    COPYING        - Copyright Notice
  184. X    Makefile    - Makefile
  185. X    strings.h
  186. X    config.h
  187. X    tune.h
  188. X    strings.c    - the main source
  189. X    limits.c    - the UNIX (trademark of AT&T) specific stuff to identify
  190. X                  an initialized data segment
  191. X    output.c    - output routines
  192. X    test_input    - a file containing the 2 characters the original strings
  193. X                  stumbled over. Unpack it with atob.
  194. X    strings.1    - manual page.
  195. X    strings.txt - manual page without nroff sequences
  196. X
  197. X2.) How to build strings.
  198. X
  199. XNow that you have strings you will want to build it.
  200. XThe program is shipped with UFLAGS undefined (see below for an explanation).
  201. XOn UNIX (trademark of AT&T) systems, you should be able to build the
  202. Xprogram by just typing "make". On non-UNIX systems you might have problems.
  203. X
  204. Xa.) edit Makefile. If you want to play it safe, set UFLAGS=-DSAFETY_FIRST.
  205. X    strings should now compile without any problems.
  206. X    You won't get the UNIX specific stuff: the program does not
  207. X    try to identify the initialized data segment.
  208. X
  209. Xb.) If you don't want to play it safe, but rather you want to configure
  210. X    strings to your system, take a look at config first. There is a
  211. X    list of systems. If one of these is yours, edit Makefile and
  212. X    set UFLAGS to nothing. When compiling the defines for the system
  213. X    are used.
  214. X    WARNING: some things may differ between different versions of the
  215. X    same system. On some machines there is no easy way to distinguish
  216. X    between such versions.
  217. X    If you were wrong, and the system you are using is not in the
  218. X    list of known symbols, the minimal defaults, like in a.) will be
  219. X    used.
  220. X
  221. Xc.) You want to configure strings, and your system is not in the list
  222. X    of known systems.
  223. X    Edit Makefile and set UFLAGS=-DUSE_USER_DEFINES.
  224. X    Edit tune.h and set things up for your system. The variables are
  225. X    commented.
  226. X
  227. XThere are 3 header files. The inclusion works like this.
  228. X(you can skip this)
  229. X
  230. X        (reading strings.h)
  231. X               |
  232. X               v
  233. X        (including config.h)
  234. X               |
  235. X               v
  236. X    <----- is SAFETY_FIRST defined?
  237. X    |          |
  238. X    |          | -
  239. X    |          v                      +
  240. X    |  is USE_USER_DEFINES defined? ---->use stuff from tune.h ---> continue
  241. X    |          |
  242. X    |          | -
  243. X    |          v
  244. X    |      is this machine 1 ?
  245. X    |          |
  246. X    |          | -
  247. X    |          v
  248. X    |      is this machine 2 ?
  249. X    |          |
  250. X    |          | -
  251. X    |          v
  252. X    |         ...
  253. X    |          |
  254. X    |          | -
  255. X    v          v
  256. X    use safe defaults
  257. X    |
  258. X    v
  259. X    continue
  260. X
  261. XThe program, or rather the headerfiles know about the following machines:
  262. X
  263. X- VAX 11/780 (4.3 BSD) by "unix" and "vax" and not "ultrix"
  264. X- SIEMENS PC-MX2 (SINIX v2.1) by "nsc3200" and "sinix" and "ns16000"
  265. X- Sun 3/260 (SunOS 3.5) by "unix" and "sun" and "mc68020"
  266. X- VAX 6800 (Ultrix 2.1) by "unix" and "ultrix" and "bsd4_2"    
  267. X- uVAX (VMS 5.1) by "vms" and "vax"
  268. X
  269. X3.) Why is this strings better than the standard one?
  270. X
  271. X    a.) This version of strings is at least 4 times faster than the original
  272. X        one. If the minimal string length is set to something else, it might
  273. X        even be 10 times faster.
  274. X    b.) The original one had several bugs.
  275. X    c.) This one is public domain. You get source.
  276. X
  277. X    ad a.)
  278. X        Here are results of some tests:
  279. X
  280. X        machine: PC-MX2,   OS: SINIX v2.1        file: /vmsinix    (289084)
  281. X        old :        u    43.6        s    1.1            =    44.7
  282. X        new :        u     3.8        s    2.3            =     6.1
  283. X
  284. X        machine: VAX 11/780       OS: 4.3BSD        file: /vmunix    (329728)
  285. X        old :        u    18.0        s    2.7            =    20.7
  286. X        new :        u     1.5        s    0.9            =     2.4
  287. X
  288. X        machine: SUN 3/260        OS: SunOS 3.5     file: /vmunix    (558359)
  289. X        old :        u     6.5        s    0.6            =     7.1
  290. X        new :        u     1.6        s    0.2            =     1.8
  291. X
  292. X        machine: VAX 6800         OS: Ultrix 2.1    file: /vmunix    (662528)
  293. X        old :        u     5.2        s    0.4            =     5.6
  294. X        new :        u     0.6        s    0.0            =     0.6
  295. X
  296. X        User, sys and total times in seconds.
  297. X
  298. X    ad b.)
  299. X        The original strings
  300. X        - thinks control-L (0x0c) is a printable character
  301. X        - under some circumstances thinks 0x80 is printable. In the
  302. X          package there is a file, test_input. Unpack this file with
  303. X          atob. The file now contains several lines of characters including
  304. X          a line with control-L and one with a 0x80. The original strings
  305. X          errs for both cases.
  306. X        - did not get the start address of the initialized data right on
  307. X          some systems.
  308. X        - had problems when dealing with the standard input.
  309. X        The first two bugs have been found on 43BSD, SunOS and ULTRIX, the
  310. X        third only on MX2 SINIX v2.1.
  311. X
  312. X4.) What about bugs?
  313. X
  314. X    If you find bugs, tell me. If you fixed them or if you made an
  315. X    extension which really is one, drop me a note.
  316. X
  317. X5.) Notes
  318. X
  319. X    This program is about 7 times faster than the orignal one.
  320. X    There are two reasons for this:
  321. X    - It does not use fgetc/fputc to get or put characters, but
  322. X      reads characters in blocks. It does not copy them but rather moves
  323. X      pointers around on the input buffer. There is no
  324. X      procedure call needed to get at each character.
  325. X      When a sequence is found, it is put into the output buffer in one
  326. X      block, thus there is no need, like in fputc, to check for possible
  327. X      overflow for each character.
  328. X    - When the program searches for a sequence of printable characters
  329. X      it only examines each min_str_len character instead of each one.
  330. X       min_str_len defaults to 4 and can be set with command line option
  331. X      like "strings -3".
  332. X
  333. X    It can be sped up some more, but then it would be difficult to port
  334. X    it to different systems.
  335. X    Example:
  336. X    Currently the program takes 6.0 seconds on MX2 for /vmsinix.
  337. X    The improved version only needs 5.5 seconds. It is also much smaller:
  338. X    6976 bytes compared to 10596.
  339. X    Ways to improve the program:
  340. X    - On some machines another method to test whether a character is printable
  341. X      will be faster. Now the program uses an array (isp), uses a character
  342. X      cast to a (signed) integer as index into this array (isp_mid is the
  343. X      base from which offsets are computed).
  344. X      On MX2, and, if I believe my tests, on VAX, it is faster, to use
  345. X      unsigned characters as index into this array.
  346. X      If you want to play around with this, just change CHAR_TYPE to
  347. X      'unsigned byte' and define the macro IS_PRINTABLE accordingly to
  348. X      '(isp[c])'
  349. X    - It makes a difference (although a small one), what basic type you
  350. X      choose for the isp array. On MX2 short is best, but char is nearly
  351. X      as good.
  352. X    - You can make it smaller. The program does not need stdio. But
  353. X      exit normally closes file descriptors, and therefore includes a
  354. X      large part of the stdio stuff. Well, about 4 K on some systems.
  355. X      If you know what your exit does, you can substitute a suitable
  356. X      routine of your own. E.g. on MX2, exit calls _cleanup, which
  357. X      only closes all open file descriptors. As I know that only the
  358. X      standard descriptors are open at the end of the program, I can
  359. X      write a _cleanup which only does a close on 0, 1, and 2.
  360. X
  361. X    The savings that you get are almost invisible, they are not easily
  362. X    portable, but rather require a certain amount of research on part
  363. X    of the person doing the  porting. I chose not to fit the programs with
  364. X    options to adjust these things.
  365. X
  366. X    There are still some DEBUG statements in the code. You get them
  367. X    if you set DEBUGFLAGS=-DDEBUG.
  368. X
  369. X6.) Status
  370. X
  371. X    This program is placed into the public domain.
  372. X    The Copyright Notice in COPYING applies.
  373. X
  374. XAbsorb, apply and enjoy,
  375. X        Michael Greim
  376. END_OF_FILE
  377. if test 7601 -ne `wc -c <'README'`; then
  378.     echo shar: \"'README'\" unpacked with wrong size!
  379. fi
  380. # end of 'README'
  381. fi
  382. if test -f 'config.h' -a "${1}" != "-c" ; then 
  383.   echo shar: Will not clobber existing file \"'config.h'\"
  384. else
  385. echo shar: Extracting \"'config.h'\" \(2765 characters\)
  386. sed "s/^X//" >'config.h' <<'END_OF_FILE'
  387. X/*
  388. X * This file is used within strings.
  389. X * You can add specific defines for a machine below. Define neither
  390. X * SAFETY_FIRST nor USE_USER_DEFINES
  391. X * Defines for your current machine should go in tune.h. Define
  392. X * USE_USER_DEFINES.
  393. X *
  394. X * sccsid : @(#)  config.h  (v6.5 5/22/89)
  395. X *
  396. X * FOUND will contain a string telling what defines have been used.
  397. X */
  398. X
  399. X# ifndef SAFETY_FIRST
  400. X#    ifdef USE_USER_DEFINES
  401. X#        define FOUND        "Using the user defines."
  402. X#        include "tune.h"
  403. X#    else USE_USER_DEFINES
  404. X        /*
  405. X         * Add (all) defines for your machine here.
  406. X         */
  407. X#        if defined(nsc32000) && defined(sinix) && defined(ns16000)
  408. X#            define FOUND                        "Using defaults for sinix MX2."
  409. X#            define FCNTL                        2
  410. X#            define FAST_COPY(from,to,count)        bcopy(from,to,count)
  411. X#            define WHAT_LSEEK                    1
  412. X#            define I_SPECIAL
  413. X#            define IN_BUF_LEN                    1024
  414. X#            define OUT_BUF_LEN                    8192
  415. X#            define THRESHOLD                    1024
  416. X#        endif /* nsc32000 && sinix && ns16000 */
  417. X#        if defined(unix) && defined(vax) && !defined(ultrix)
  418. X#            define FOUND                        "Using defaults for VAX (BSD?)."
  419. X#            define FCNTL                        1
  420. X#            define FAST_COPY(from,to,count)        bcopy(from,to,count)
  421. X#            define WHAT_LSEEK                    1
  422. X#            define I_SPECIAL
  423. X#            define IN_BUF_LEN                    4096
  424. X#            define OUT_BUF_LEN                    16384
  425. X#            define THRESHOLD                    4096
  426. X#        endif /* vax */
  427. X#        if defined(unix) && defined(sun) && defined(mc68020)
  428. X#            define FOUND                        "Using defaults for SUN (SUN OS 3.*)."
  429. X#            define FCNTL                        1
  430. X#            define FAST_COPY(from,to,count)        bcopy(from,to,count)
  431. X#            define WHAT_LSEEK                    1
  432. X#            define I_SPECIAL
  433. X#            define IN_BUF_LEN                    4096
  434. X#            define OUT_BUF_LEN                    16384
  435. X#            define THRESHOLD                    4096
  436. X#        endif /* sun */
  437. X#        if defined(unix) && defined(ultrix) && defined(bsd4_2)
  438. X#            define FOUND                        "Using defaults for VAX (ULTRIX 2.0)"
  439. X#            define FCNTL                        1
  440. X#            define FAST_COPY(from,to,count)        bcopy(from,to,count)
  441. X#            define WHAT_LSEEK                    1
  442. X#            define I_SPECIAL
  443. X#            define IN_BUF_LEN                    4096
  444. X#            define OUT_BUF_LEN                    16384
  445. X#            define THRESHOLD                    4096
  446. X#        endif /* vax ultrix */
  447. X#        if defined(vms) && defined(vax)
  448. X#            define FOUND                        "Using defaults for VAX (VMS)"
  449. X/* don't define FCNTL, O_RDONLY flag is in file.h and is 0 */
  450. X#            define FAST_COPY(from,to,count)        memcpy(to,from,count)
  451. X#            define WHAT_LSEEK                    2
  452. X/*            define I_SPECIAL*/
  453. X#            define IN_BUF_LEN                    4096
  454. X#            define OUT_BUF_LEN                    16384
  455. X#            define THRESHOLD                    4096
  456. X#        endif /* vax ultrix */
  457. X#    endif USE_USER_DEFINES
  458. X# endif SAFETY_FIRST
  459. X
  460. X# ifndef FOUND
  461. X/*
  462. X * We have to use the defaults.
  463. X */
  464. X#    define FOUND                            "Using minimal defaults."
  465. X/* dont    define FCNTL */
  466. X/* FAST_COPY will be a real routine */
  467. X#    define WHAT_LSEEK                        1
  468. X/* don't define I_SPECIAL */
  469. X#    define IN_BUF_LEN                        1024
  470. X#    define OUT_BUF_LEN                        8192
  471. X#    define THRESHOLD                        1024
  472. X
  473. X# endif FOUND
  474. END_OF_FILE
  475. if test 2765 -ne `wc -c <'config.h'`; then
  476.     echo shar: \"'config.h'\" unpacked with wrong size!
  477. fi
  478. # end of 'config.h'
  479. fi
  480. if test -f 'limits.c' -a "${1}" != "-c" ; then 
  481.   echo shar: Will not clobber existing file \"'limits.c'\"
  482. else
  483. echo shar: Extracting \"'limits.c'\" \(1183 characters\)
  484. sed "s/^X//" >'limits.c' <<'END_OF_FILE'
  485. Xstatic char * sccsid = "@(#)  limits.c  (v6.2 5/19/89)";
  486. X
  487. X# include "strings.h"
  488. X
  489. X# ifdef I_SPECIAL
  490. X
  491. X#    ifdef sun
  492. X#        include <sys/exec.h>
  493. X#    endif sun
  494. X#    include <a.out.h>
  495. X
  496. Xget_limits (fd, first, last)
  497. Xint fd;
  498. XLSEEK_TYPE * first, * last;
  499. X/*
  500. X * Have a look into the input file open under fd.
  501. X * If we think it is an object file, than get the start and
  502. X * size of initialized data and set
  503. X * *first : address where examination of file will start
  504. X * *last  : first address which will not be examined.
  505. X */
  506. X{
  507. X    register int i;
  508. X    struct exec e;
  509. X    LSEEK_TYPE l;
  510. X
  511. X    *first = (LSEEK_TYPE)0;
  512. X    *last = (LSEEK_TYPE)(-1);
  513. X    if (lseek (fd, (LSEEK_TYPE)0, 0) != (LSEEK_TYPE)0) {
  514. X# ifdef DEBUG
  515. X        fprintf (prot, "Input not seekable\n");
  516. X# endif
  517. X        return;
  518. X    }
  519. X    i = read (fd, (char*)(&e), sizeof (e));
  520. X    if (i != sizeof(e)) {
  521. X# ifdef DEBUG
  522. X        fprintf (prot, "file too small\n");
  523. X# endif
  524. X        return;
  525. X    }
  526. X    if (N_BADMAG(e)) {
  527. X# ifdef DEBUG
  528. X        fprintf (prot, "bad magic\n");
  529. X# endif
  530. X        return;
  531. X    }
  532. X    l = N_TXTOFF(e) + e.a_text;
  533. X# ifdef DEBUG
  534. X    fprintf (prot, "start of initialized data at %ld\n", (long)i);
  535. X    fprintf (prot, "length = %1ld\n", (long)(e.a_data));
  536. X# endif
  537. X    *first = l;
  538. X    *last = l + e.a_data;
  539. X}
  540. X
  541. X# endif I_SPECIAL
  542. END_OF_FILE
  543. if test 1183 -ne `wc -c <'limits.c'`; then
  544.     echo shar: \"'limits.c'\" unpacked with wrong size!
  545. fi
  546. # end of 'limits.c'
  547. fi
  548. if test -f 'output.c' -a "${1}" != "-c" ; then 
  549.   echo shar: Will not clobber existing file \"'output.c'\"
  550. else
  551. echo shar: Extracting \"'output.c'\" \(5953 characters\)
  552. sed "s/^X//" >'output.c' <<'END_OF_FILE'
  553. Xstatic char * sccsid = "@(#)  output.c  (v6.5 5/19/89)";
  554. X/*
  555. X * Output routines for 'strings'.
  556. X * We roll our own here, because stdio either expects NUL terminated
  557. X * strings, which we don't have, or tests for buffer overflow at each
  558. X * character. But we know how much characters will be added to the
  559. X * output block, so we can make do with two or three tests per sequence
  560. X * of printable characters.
  561. X *
  562. X * Sequences are stuffed into the output buffer, even temporarily when
  563. X * we could not decide what to do with them, yet had to remember the
  564. X * characters. When a temporary sequence is made permanent or a
  565. X * permanent sequence added, and the new length of data in the output
  566. X * buffer exceeds a threshold, it is output.
  567. X * If the buffer overflows in between it is extended with a call to
  568. X * realloc. This rarely ever happens, but if it happens, then
  569. X * you will rather have strings to be slowing down than dump core.
  570. X */
  571. X
  572. X# include "strings.h"
  573. X
  574. X/*
  575. X * The characters in out_buf until num_out_buf are already accepted.
  576. X * level points at the end of all characters in out_buf, even the
  577. X * temporarily saved ones.
  578. X * saved is the number of characters temporarily saved.
  579. X * Note that level and saved are not the same. If there are number before
  580. X * the sequences, then buf+num_out_buf+saved != level !!
  581. X * Note that sometimes I have to compute the number of characters between
  582. X * out_buf and level. I do this by subtracting the two pointers. I assume
  583. X * that the result is int or convertible to int, but I don't have the
  584. X * authority at hand to prove this.
  585. X */
  586. XCHAR_TYPE * out_buf;
  587. Xint num_out_buf = 0;                /* numbers of chars in out_buf */
  588. XCHAR_TYPE * level;
  589. Xint buf_len;
  590. Xint saved = 0;
  591. X
  592. Xextern int ind_offset;
  593. Xextern int ind_prefix;
  594. Xextern CHAR_TYPE buf[];
  595. Xextern LSEEK_TYPE offset;
  596. Xextern char * cur_file_name;
  597. X
  598. Xextern char * malloc ();
  599. Xextern char * realloc ();
  600. X
  601. Xinit_output ()
  602. X{
  603. X    out_buf = (CHAR_TYPE *) malloc (sizeof (CHAR_TYPE) * OUT_BUF_LEN);
  604. X    level = out_buf;
  605. X    num_out_buf = 0;
  606. X    buf_len = OUT_BUF_LEN;
  607. X}
  608. X
  609. Xflush_output ()
  610. X/*
  611. X * Num_out_buf characters from the buffer are written.
  612. X */
  613. X{
  614. X    if (num_out_buf > 0) {
  615. X# ifdef DEBUG
  616. X        fprintf (prot, "flush_output : write %d chars\n", num_out_buf);
  617. X# endif
  618. X        if (write (1, out_buf, num_out_buf) != num_out_buf) {
  619. X            out ("PANIC : write error\n");
  620. X            exit (1);
  621. X        }
  622. X        num_out_buf = 0;
  623. X    }
  624. X    level = out_buf;
  625. X}
  626. X
  627. Xstatic
  628. Xmake_room (n)
  629. Xregister int n;
  630. X/*
  631. X * Must reallocate.
  632. X * Buffer is enlarged by at least IN_BUF_LEN characters. The largest
  633. X * piece which has to be put into the buffer will be at most IN_BUF_LEN
  634. X * characters. If there is a sequence of puts, the buffer will be enlarged
  635. X * each time. This should happen very rarely.
  636. X */
  637. X{
  638. X    register int i;
  639. X# ifdef DEBUG
  640. X    fprintf (prot, "make_room :: REALLOC realloc called.\n");
  641. X    fflush (prot);
  642. X# endif
  643. X    /*
  644. X     * Level is a pointer into out_buf. We have to save it here and
  645. X     * restore it later, because realloc might cause a copying of the
  646. X     * contents of out_buf to a new address.
  647. X     */
  648. X    i = level - out_buf;
  649. X    buf_len += n>IN_BUF_LEN?n:IN_BUF_LEN;
  650. X# ifdef DEBUG
  651. X    fprintf (prot, "make_room :: output buffer will be enlarged to %d\n", buf_len);
  652. X# endif
  653. X    out_buf = (CHAR_TYPE *) realloc (out_buf, (unsigned int)buf_len);
  654. X    if (out_buf == NULL) {            /* panic */
  655. X        (void)write (2, "REALLOC ERROR.\n", 15);
  656. X        exit (1);
  657. X    }
  658. X    level = out_buf + i;
  659. X}
  660. X
  661. Xvoid
  662. Xadd_cur_file_name ()
  663. X/*
  664. X * Only called if command line flag '-p' was specified.
  665. X * Add the name of the current input file to the output stream.
  666. X */
  667. X{
  668. X    register int i;
  669. X
  670. X    if (cur_file_name == NULL)
  671. X        return;
  672. X    i = strlen (cur_file_name);
  673. X    /*
  674. X     * Is there space for (i+1) characters at the end of the output buffer?
  675. X     * If not, flush it.
  676. X     */
  677. X    if ((int)(level - out_buf) + i + 1 > buf_len)
  678. X        make_room (i+1);
  679. X    FAST_COPY (cur_file_name, level, i);
  680. X    level += i;
  681. X    *level++ = ':';
  682. X}
  683. X
  684. Xappend (b1, b2, ind_perm)
  685. Xregister CHAR_TYPE * b1, * b2;
  686. Xint ind_perm;
  687. X/*
  688. X * Append a sequence permanently. Set the pointers.
  689. X * If there are more than THRESHOLD characters then write them.
  690. X */
  691. X{
  692. X    register int n;
  693. X
  694. X    /*
  695. X     * If the user wants it and this is the first part of a sequence,
  696. X     * add name of current file as prefix.
  697. X     */
  698. X    if (ind_prefix && saved == 0)
  699. X        add_cur_file_name ();
  700. X    /*
  701. X     * If there are no saved characters and the user wants offsets,
  702. X     * then we have to add an offset first.
  703. X     */
  704. X    if (ind_offset && saved == 0)
  705. X        output_offset (b1);
  706. X    /*
  707. X     * Is there enough space in out outbuf ?
  708. X     */
  709. X    n = b2 - b1;
  710. X    if ((int)(level - out_buf) + n + 1 > buf_len)
  711. X        make_room (n);
  712. X    /*
  713. X     * Copy the sequence. It may be empty, so don't forget to add a LF here.
  714. X     */
  715. X    if (n > 0) {
  716. X        FAST_COPY (b1, level, n);
  717. X        level += n;
  718. X    }
  719. X    if (ind_perm == 1) {
  720. X        *level++ = '\n';
  721. X        /*
  722. X         * There may be some temporarily saved characters in out_buf. Make
  723. X         * them permanent.
  724. X         */
  725. X        num_out_buf = level - out_buf;
  726. X        /*
  727. X         * If necessary, write.
  728. X         */
  729. X        if (num_out_buf > THRESHOLD)
  730. X            flush_output ();
  731. X        saved = 0;
  732. X    } else
  733. X        saved = n;
  734. X}
  735. X
  736. Xoutput_offset (b1)
  737. XCHAR_TYPE * b1;
  738. X/*
  739. X * Convert n to its character representation in decimal and append this
  740. X * at the end of the output buffer.
  741. X * Normally we output 7 characters. If the number needs more we expand.
  742. X */
  743. X{
  744. X    register int i;
  745. X    register long j;
  746. X    register LSEEK_TYPE l;
  747. X    CHAR_TYPE * b;
  748. X
  749. X    l = offset + (int)(b1 - buf);
  750. X    /*
  751. X     * How many characters must we output ?
  752. X     */
  753. X    for (i = 7, j = 10000000L; l >= j; j *= 10, i++);
  754. X
  755. X    /*
  756. X     * Is there space for (i+1) characters at the end of the output buffer?
  757. X     * If not, flush it.
  758. X     */
  759. X    if ((int)(level - out_buf) + i+1 > buf_len)
  760. X        make_room (i+1);
  761. X
  762. X    b = level;
  763. X    level += i+1;
  764. X
  765. X    b[i--] = ' ';
  766. X    /*
  767. X     * Convert the number.
  768. X     */
  769. X    do {
  770. X        b[i--] = '0' + l % 10;
  771. X        l /= 10;
  772. X    } while (l != 0);
  773. X    /*
  774. X     * Add some blanks in front of number
  775. X     */
  776. X    for (; i >= 0; i--)
  777. X        b [i] = ' ';
  778. X}
  779. X
  780. X# ifdef DEBUG
  781. Xout (s)
  782. X{
  783. X    fputc (s, stderr);
  784. X}
  785. X# else DEBUG
  786. X/*
  787. X * The main program calls a routine called 'out'.
  788. X */
  789. Xout (s)
  790. Xregister char * s;
  791. X{
  792. X    (void)write (2, s, strlen(s));
  793. X}
  794. X# endif DEBUG
  795. END_OF_FILE
  796. if test 5953 -ne `wc -c <'output.c'`; then
  797.     echo shar: \"'output.c'\" unpacked with wrong size!
  798. fi
  799. # end of 'output.c'
  800. fi
  801. if test -f 'strings.1' -a "${1}" != "-c" ; then 
  802.   echo shar: Will not clobber existing file \"'strings.1'\"
  803. else
  804. echo shar: Extracting \"'strings.1'\" \(4863 characters\)
  805. sed "s/^X//" >'strings.1' <<'END_OF_FILE'
  806. X.TH STRINGS 1 "5/22/89"
  807. X.SH NAME
  808. Xstrings - find and output the printable strings in a file
  809. X.SH SYNOPSIS
  810. X.B strings
  811. X[
  812. X.B -option
  813. X] [
  814. X.B filename
  815. X] ...
  816. X.br
  817. Xoption is one of a,-,o,p,t,v,e,c or a number.
  818. X.SH DESCRIPTION
  819. X.I strings
  820. Xlooks for sequences of printable characters in a file and outputs them, if
  821. Xthey are longer than \fInumber\fR. Default for \fInumber\fR is 4.
  822. X.br
  823. XIf
  824. X.I strings
  825. Xidentifies a file as containing an object, it will only scan the initialized
  826. Xdata segment of the object. If you specified either the "-a" or "-" flags
  827. Xit will scan the whole file.
  828. X.br
  829. XIf there is more than one filename specified, the name of the file
  830. Xis output before the stuff from that file.
  831. X.br
  832. XIf there is no filename specified \fIstrings\fR will read from standard input.
  833. X.SH OPTIONS
  834. X.B \-
  835. X.B \-a
  836. X'in +3
  837. Xexamine the entire file for sequences of printable characters. Default on
  838. XUNIX (trademark of AT&T) systems is to examine only the segment of
  839. Xinitialized data. On systems where such a segment does not exist, the
  840. Xoptions "-a" and "-" do not exist.
  841. X.in -3
  842. X.B \-o
  843. X'in +3
  844. Xprecede each output string by its offset from the
  845. Xbeginning of the file (in decimal).
  846. XThe number is output with (at least) 7 digits, filled with
  847. Xblanks. Then follows a blank, then the found string.
  848. XIf these 7 digits are not sufficent to hold the offset, \fIstrings\fR will use
  849. X8 digits or as much as necessary (and possible :-).
  850. X.in -3
  851. X.B number
  852. X'in +3
  853. Xonly output sequences longer than or as long as \fBnumber\fR. Only decimal
  854. Xvalues are accepted.
  855. X.in -3
  856. X.B \-p
  857. X'in +3
  858. Xprefix each output with the name of the input file. This is useful e.g. if
  859. X\fIstrings\fR is used on a list of files and \fIfgrep\fR is used to
  860. Xsearch for a certain string. When this string is found you will get
  861. Xthe name of the file the string was found in.
  862. X.in -3
  863. X.B \-e
  864. X'in +3
  865. Xthe next argument is interpreted as a filename, even if it starts with a "-".
  866. XThus "strings -e -a" will try to read from file "-a".
  867. X.in -3
  868. X.B \-t
  869. X'in +3
  870. XTAB is considered a printable character.
  871. X.in -3
  872. X.B \-c
  873. X'in +3
  874. Xoutput only strings which end with a NUL or LF character. Most strings
  875. Xin C programs will result in strings like this.
  876. X.in -3
  877. X.B \-v
  878. X'in +3
  879. Xprint information about \fIstrings\fR version, including the flags with
  880. Xwhich it was compiled. This may be uninteresting to the normal user,
  881. Xbut is quite informative when porting to another system. Nothing
  882. Xelse is output, the program exits immediately afterwards.
  883. X.in -3
  884. X.br
  885. X.LP
  886. XOptions can be specified in a single word. They apply to all files specified.
  887. XIt is an error for an option to be specified twice.
  888. XThe following invocations
  889. Xare correct:
  890. X.sp
  891. X.in +4
  892. Xstrings -ao12 m1 m2 m3
  893. X.br
  894. Xstrings -a -ot -12 m1
  895. X.br
  896. Xstrings -a m1 -o m2
  897. X.br
  898. Xstrings - -o
  899. X.br
  900. Xstrings core -a blabla -o rhabarber -12
  901. X.in -4
  902. X.sp
  903. XThe following invocations are incorrect:
  904. X.sp
  905. X.in +4
  906. Xstrings -a - BBB
  907. X.br
  908. Xstrings -aa m
  909. X.br
  910. Xstrings -12a14 core
  911. X.br
  912. X.in -4
  913. X.SH AUTHOR
  914. XMichael Greim
  915. X.sp
  916. Xgreim@sbsvax.uucp
  917. X.br
  918. Xgreim@sbsvax.informatik.uni-saarland.dbp.de
  919. X.SH DIAGNOSTICS
  920. XDiagnostics are always written to file descriptor 2, i.e. if a file cannot
  921. Xbe opened or malloc runs out of memory.
  922. X.br
  923. XIf the user makes an error when invoking \fIstrings\fR, a table with
  924. Xthe correct syntax will be output.
  925. X.br
  926. XIf the output buffer overflows, the program tries to enlarge it using
  927. Xrealloc. If this fails, it prints a message and exits
  928. Ximmediately.
  929. X.SH BUGS
  930. X.br
  931. X\fIStrings\fR does not inform the user, whether it has found an object file
  932. Xor not.
  933. X.sp
  934. XIf you have a file which contains a long sequence of printable characters,
  935. Xe.g. about as long as to become as large as your computers memory size,
  936. X\fIstrings\fR might run out of memory. It will print "REALLOC error" and
  937. Xexit.
  938. X.sp
  939. XIf a file contains a magic number for object files, \fIstrings\fR thinks
  940. Xit has found an object file and interpretes the bytes at a certain location
  941. Xas offsets into the file. This may lead to errors, but \fIstrings\fR
  942. Xdoes not tell the user about it.
  943. X.sp
  944. XThe way to identify an object file, or even the concept of initialized
  945. Xdata may vary with systems. When \fIstrings\fR is compiled one can turn
  946. Xoff this special feature (I_SPECIAL). Consequently the options
  947. X\fI-a\fR and \fI-\fR
  948. Xare no longer valid. Invoke \fIstrings\fR with an invalid option to
  949. Xget a list of possible options.
  950. X.sp
  951. XIf \fIstrings\fR is invoked on the standard input it fills up its buffer
  952. Xbefore it outputs anything. If you enter a line at a time, it
  953. Xtakes some time before you see the first output.
  954. X.sp
  955. XIf \fIstrings\fR is invoked on the standard input, it does not try to
  956. Xrecognize an object file, but acts as if the flags \fI-a\fR or \fI-\fR
  957. Xhad been set.
  958. X.br
  959. XThe option "c" will not get all C strings. If you use something like
  960. X.nf
  961. X       printf ("Say something\\r\\n");
  962. X.fi
  963. Xand you specify "c" when invoking \fIstrings\fR
  964. Xyou will not get the string, because it does not end with NUL or LF.
  965. END_OF_FILE
  966. if test 4863 -ne `wc -c <'strings.1'`; then
  967.     echo shar: \"'strings.1'\" unpacked with wrong size!
  968. fi
  969. # end of 'strings.1'
  970. fi
  971. if test -f 'strings.c' -a "${1}" != "-c" ; then 
  972.   echo shar: Will not clobber existing file \"'strings.c'\"
  973. else
  974. echo shar: Extracting \"'strings.c'\" \(13637 characters\)
  975. sed "s/^X//" >'strings.c' <<'END_OF_FILE'
  976. Xstatic char * sccsid = "@(#)  strings.c  (v1.6.9 5/23/89)";
  977. X/*
  978. X * strings
  979. X * =======
  980. X *
  981. X * Find and output the printable strings with a certain minimal length or
  982. X * more in any files.
  983. X *
  984. X * This is a rewrite of 4BSD strings, which had some errors:
  985. X * - ^L is a printable character (4.3BSD, SUN OS)
  986. X * - 0x80 is a printable character (4.3BSD, SUN OS)
  987. X * - on some systems (MX2) it does not get the segment of initialized data
  988. X *   correctly
  989. X *
  990. X * A printable string is any string of printable characters. A printable
  991. X * character is any obvious one, plus blank. If flag -t was specified TAB
  992. X * is considered a printable character too. If flag -c was specified
  993. X * on the command line, only strings are output, which are followed
  994. X * by LF or NUL, just like the original BSD manual entry claimed.
  995. X *
  996. X */
  997. X
  998. X# include "strings.h"
  999. X
  1000. X# include <ctype.h>
  1001. X
  1002. Xchar isp [256];
  1003. Xchar * isp_mid;
  1004. X# define IS_PRINTABLE(c)    (isp_mid[c])
  1005. X
  1006. Xint fd;
  1007. X
  1008. XCHAR_TYPE buf [IN_BUF_LEN];
  1009. X
  1010. Xint ind_whole    = 0;        /* Shall we examine whole file ? */
  1011. Xint ind_offset    = 0;        /* Offsets required ? */
  1012. Xint min_str_len = 4;        /* If a string has more characters, it is output */
  1013. Xint ind_file    = 0;        /* # of filenames in command */
  1014. Xint ind_c        = 0;        /* Only strings ending with NUL or LF ? */
  1015. Xint ind_tab        = 0;        /* Is TAB a printable character ? */
  1016. Xint ind_prefix  = 0;        /* should the filename be added before string ? */
  1017. Xint ind_version = 0;        /* print version information ? */
  1018. X
  1019. XLSEEK_TYPE offset;
  1020. X
  1021. Xchar * cur_file_name;
  1022. X
  1023. Xextern CHAR_TYPE * out_buf, * level;
  1024. Xextern int num_out_buf;
  1025. Xextern int saved;
  1026. X
  1027. X# define SEARCH        1
  1028. X# define DECIDE        2
  1029. X# define TRY         3
  1030. X
  1031. Xusage (n)
  1032. Xint n;
  1033. X{
  1034. X    out ("usage: strings [options] [file ...]\n");
  1035. X# ifdef I_SPECIAL
  1036. X    out ("-a : look in whole file. Default : only look in initialized data\n");
  1037. X    out ("-  : the same as -a\n");
  1038. X# endif
  1039. X    out ("-o : output offset in decimal before each string.\n");
  1040. X    out ("-N : only output sequences of length >= N; N is a number > 0.\n");
  1041. X    out ("-c : only output C strings; terminated by \\0 or \\n\n");
  1042. X    out ("-e : the next word is taken as a filename, even if it starts with '-'.\n");
  1043. X    out ("-t : TAB is considered a printable character too.\n");
  1044. X    out ("-p : the name of the input file is output before each string.\n");
  1045. X    out ("-v : only print version information, examine no files.\n");
  1046. X# ifdef I_SPECIAL
  1047. X    out ("Options can be combined like '-a20ot'.\n");
  1048. X# else
  1049. X    out ("Options can be combined like '-20o'.\n");
  1050. X    out ("The whole file is scanned.\n");
  1051. X# endif
  1052. X    exit (n);
  1053. X}
  1054. X
  1055. Xout_int (n)
  1056. Xregister int n;
  1057. X{
  1058. X    char s [20];
  1059. X    register int i;
  1060. X    s [19] = '\0';
  1061. X    i = 18;
  1062. X    if (n == 0) {
  1063. X        s [18] = '0';
  1064. X        i = 17;
  1065. X    }
  1066. X    while (n != 0) {
  1067. X        s[i--] = '0' + (n % 10);
  1068. X        n /= 10;
  1069. X    }
  1070. X    out (s+i+1);
  1071. X}
  1072. X
  1073. Xprint_version()
  1074. X{
  1075. X    out (sccsid); out ("\n\n");
  1076. X    out ("Compilation flags:\n");
  1077. X    out ("FOUND = \""); out (FOUND); out ("\"\n");
  1078. X# ifdef FCNTL
  1079. X    out ("FCNTL = "); out_int (FCNTL); out ("\n");
  1080. X# else
  1081. X    out ("FCNTL is not defined.\n");
  1082. X# endif FCNTL
  1083. X# ifdef FAST_COPY
  1084. X    out ("FAST_COPY is defined.\n");
  1085. X# else
  1086. X    out ("FAST_COPY is not defined.\n");
  1087. X# endif FAST_COPY
  1088. X# ifdef WHAT_LSEEK
  1089. X    out ("WHAT_LSEEK = "); out_int (WHAT_LSEEK); out ("\n");
  1090. X# else
  1091. X    out ("WHAT_LSEEK is not defined.\n");
  1092. X# endif WHAT_LSEEK
  1093. X# ifdef I_SPECIAL
  1094. X    out ("I_SPECIAL is defined.\n");
  1095. X# else
  1096. X    out ("I_SPECIAL is not defined.\n");
  1097. X# endif I_SPECIAL
  1098. X    out ("IN_BUFLEN  = "); out_int (IN_BUF_LEN); out ("\n");
  1099. X    out ("OUT_BUFLEN = "); out_int (OUT_BUF_LEN); out ("\n");
  1100. X    out ("THRESHOLD  = "); out_int (THRESHOLD); out ("\n");
  1101. X}
  1102. X
  1103. Xoptions (ac, av, f)
  1104. Xint ac;
  1105. Xchar * av [];
  1106. Xchar ** f;
  1107. X{
  1108. X    register int i, j;
  1109. X    int take_file = 0;                /* is the next word a file ? */
  1110. X    int had_whole, had_offset, had_min_str_len;
  1111. X    int had_c, had_tab, had_prefix, had_version;
  1112. X
  1113. X    had_whole = had_offset = had_min_str_len = had_c = had_tab = 0;
  1114. X    had_prefix = had_version = 0;
  1115. X    for (i = 1; i < ac; i++) {
  1116. X        if (take_file == 0 && av[i][0] == '-') {
  1117. X            if (av[i][1] == '\0') {
  1118. X                if (had_whole == 1)
  1119. X                    usage (5);
  1120. X                had_whole = 1;
  1121. X                ind_whole = 1;
  1122. X            } else {
  1123. X                for (j = 1; av[i][j] != '\0'; j++) {
  1124. X                    if ('0' <= av[i][j] && av[i][j] <= '9') {
  1125. X                        if (had_min_str_len == 1)
  1126. X                            usage (3);
  1127. X                        for (min_str_len = 0; '0' <= av[i][j]  && av[i][j] <= '9'; j++)
  1128. X                            min_str_len = min_str_len * 10 + av[i][j] - '0';
  1129. X                        j--;    /* So we don't lose a character */
  1130. X                        had_min_str_len = 1;
  1131. X                    } else
  1132. X                        switch (av[i][j]) {
  1133. X# ifdef I_SPECIAL
  1134. X                            case 'a':
  1135. X                            case '-':
  1136. X                                if (had_whole == 1)
  1137. X                                    usage (5);
  1138. X                                had_whole = 1;
  1139. X                                ind_whole = 1;
  1140. X                                break;
  1141. X# endif
  1142. X                            case 'o':
  1143. X                                if (had_offset == 1)
  1144. X                                    usage (6);
  1145. X                                had_offset = ind_offset = 1;
  1146. X                                break;
  1147. X                            case 'c':
  1148. X                                if (had_c == 1)
  1149. X                                    usage (7);
  1150. X                                had_c = ind_c = 1;
  1151. X                                break;
  1152. X                            case 'f':
  1153. X                                take_file = 1;
  1154. X                                break;
  1155. X                            case 't':
  1156. X                                if (had_tab == 1)
  1157. X                                    usage (8);
  1158. X                                had_tab = ind_tab = 1;
  1159. X                                break;
  1160. X                            case 'p':
  1161. X                                if (had_prefix == 1)
  1162. X                                    usage (9);
  1163. X                                had_prefix = ind_prefix = 1;
  1164. X                                break;
  1165. X                            case 'v':
  1166. X                                if (had_version == 1)
  1167. X                                    usage (10);
  1168. X                                had_version = ind_version = 1;
  1169. X                                break;
  1170. X                            default:
  1171. X                                usage (8);
  1172. X                                break;
  1173. X                        }
  1174. X                }
  1175. X            }
  1176. X        } else {
  1177. X            f [ind_file++] = av[i];
  1178. X            take_file = 0;
  1179. X        }
  1180. X    }
  1181. X    if (min_str_len <= 0)
  1182. X        usage (4);
  1183. X# ifdef DEBUG
  1184. X    fprintf (prot, "ind_offset  = %3d\n", ind_offset);
  1185. X    fprintf (prot, "ind_whole   = %3d\n", ind_whole);
  1186. X    fprintf (prot, "ind_file    = %3d\n", ind_file);
  1187. X    fprintf (prot, "ind_c       = %3d\n", ind_c);
  1188. X    fprintf (prot, "min_str_len = %3d\n", min_str_len);
  1189. X    fprintf (prot, "ind_tab     = %3d\n", ind_tab);
  1190. X    fprintf (prot, "ind_prefix  = %3d\n", ind_prefix);
  1191. X    fprintf (prot, "ind_version = %3d\n", ind_version);
  1192. X    if (ind_file == 0)
  1193. X        fprintf (prot, "had no files on command line\n");
  1194. X    else {
  1195. X        fprintf (prot, "had %1d files on command line\n", ind_file);
  1196. X        for (i = 0; i < ind_file; i++)
  1197. X            fprintf (prot, "%s\n", f[i]);
  1198. X    }
  1199. X# endif
  1200. X}
  1201. X
  1202. Xinit ()
  1203. X{
  1204. X    register int i;
  1205. X    int min;
  1206. X    char c;
  1207. X
  1208. X    min = 0;
  1209. X    for (i = 0; i < 256; i++) {
  1210. X        c = i;
  1211. X        if (c < min)
  1212. X            min = c;
  1213. X    }
  1214. X    isp_mid = isp - min;
  1215. X    for (i = 0; i < 256; i++) {
  1216. X        c = i;
  1217. X        isp_mid [c] = isascii(c) && isprint(c);
  1218. X    }
  1219. X    if (ind_tab)
  1220. X        isp_mid['\t'] = 1;
  1221. X
  1222. X    init_output ();
  1223. X}
  1224. X
  1225. Xmain (argc, argv)
  1226. Xint argc;
  1227. Xchar * argv[];
  1228. X{
  1229. X    register int i;
  1230. X    char ** f;
  1231. X
  1232. X# ifdef DEBUG
  1233. X    if ((prot = fopen ("prot", "w")) == NULL) {
  1234. X        fprintf (stderr, "could not open prot\n");
  1235. X        exit (1);
  1236. X    }
  1237. X# endif
  1238. X    f = (char **) malloc ((unsigned)(sizeof (char *) * argc));
  1239. X    options (argc, argv, f);
  1240. X    if (ind_version) {
  1241. X        print_version ();
  1242. X        exit (0);
  1243. X    }
  1244. X    init ();
  1245. X
  1246. X    if (ind_file == 0)
  1247. X        strings ((char*)NULL);
  1248. X    else
  1249. X        for (i = 0; i < ind_file; i++) {
  1250. X            if (ind_file != 1)
  1251. X                out_name (f[i]);
  1252. X            strings (f[i]);
  1253. X        }
  1254. X    exit (0);
  1255. X}
  1256. X
  1257. Xout_name (b)
  1258. Xregister CHAR_TYPE * b;
  1259. X{
  1260. X    CHAR_TYPE s [45];
  1261. X    CHAR_TYPE * s2 = (CHAR_TYPE*) "  ";
  1262. X    register int n, i;
  1263. X
  1264. X    for (i = 0; i < 45; i++)
  1265. X        s [i] = '-';
  1266. X    n = strlen (s);
  1267. X    i = strlen (b);
  1268. X# ifdef DEBUG
  1269. X    fprintf (prot, "out_name :: n = %d, i = %d\n", n, i);
  1270. X# endif
  1271. X    if (n*2 + (i+2) > 80)
  1272. X        n = (80 - (i+2)) / 2;
  1273. X# ifdef DEBUG
  1274. X    fprintf (prot, "out_name :: first string is %d long.\n", n);
  1275. X# endif
  1276. X    (void) append (s, s+n, 0);
  1277. X
  1278. X    (void) append (s2, s2+1, 0);
  1279. X    (void) append (b, b+i, 0);
  1280. X    (void) append (s2, s2+1, 0);
  1281. X    
  1282. X    if (2*n + (i+2) < 80)
  1283. X        n++;
  1284. X# ifdef DEBUG
  1285. X    fprintf (prot, "out_name :: second string is %d long.\n", n);
  1286. X# endif
  1287. X    (void) append (s, s+n, 1);
  1288. X}
  1289. X
  1290. Xint
  1291. Xexamine (state, n)
  1292. Xregister int state;
  1293. Xint n;
  1294. X/*
  1295. X * Find strings of printable characters in buf and append them to
  1296. X * the output buffer, if they meet certain conditions.
  1297. X *
  1298. X * The main part of this routine is a DFA (deterministic finite automaton) with
  1299. X * three states.
  1300. X * These states are
  1301. X * SEARCH : search for a printable character by examining characters in
  1302. X *            distance min_str_len. If found, set b1 to the start
  1303. X *            of the sequence and enter state TRY.
  1304. X * TRY    : We have found a printable character. Set b2 to the first character
  1305. X *            after the end of the sequence by single stepping. Set state to
  1306. X *            DECIDE.
  1307. X * DECIDE : We have found a sequence of printable characters. If the first
  1308. X *            character after the sequence is in the buffer, then we can decide
  1309. X *            what to do with the sequence (even if flag -c was not specified).
  1310. X *            If not then the stuff is buffered, state set to TRY, and returned
  1311. X *            to the caller to read a new block of input.
  1312. X *            It is tested whether the sequence meets the requirements.
  1313. X *            Either it is output by placing it permanently into the output
  1314. X *            buffer, or it is forgotten.
  1315. X */
  1316. X{
  1317. X    register CHAR_TYPE * b, * b1, * b2, * end;
  1318. X
  1319. X    end = buf + n;
  1320. X
  1321. X    b = b1 = b2 = buf;
  1322. X    for (;b < end; b = b2+1) {
  1323. X# ifdef DEBUG
  1324. X        fprintf (prot, "state = %s; b at %d\n",
  1325. X            state == SEARCH ? "SEARCH" : (state == DECIDE ? "DECIDE" : "TRY"),
  1326. X            (int)(b - buf));
  1327. X# endif
  1328. X        b1 = b;
  1329. X        switch (state) {
  1330. X            case SEARCH:
  1331. X                /*
  1332. X                 * Search a character which might be in a sequence of
  1333. X                 * printable characters. Note that it suffices to examine
  1334. X                 * characters in distance min_str_len.
  1335. X                 */
  1336. X                for (;b2 < end && !IS_PRINTABLE(*b2); b2 += min_str_len);
  1337. X                /*
  1338. X                 * If we have stepped outside the buffer, we must examine
  1339. X                 * the end of the buffer yet.
  1340. X                 */
  1341. X                if (b2 >= end)
  1342. X                    b2 = end;
  1343. X                b1 = b2-1;
  1344. X                /*
  1345. X                 * Find the start of the current sequence.
  1346. X                 */
  1347. X                while (b1 >= buf && IS_PRINTABLE(*b1))
  1348. X                    b1--;
  1349. X                b1++;
  1350. X                if (b1 >= end)
  1351. X                    return (SEARCH);
  1352. X                /* FALL THROUGH */
  1353. X        case TRY:
  1354. X                /*
  1355. X                 * Find  the end of the current sequence. Set b2 one beyond.
  1356. X                 */
  1357. X                while (b2 < end && IS_PRINTABLE(*b2))
  1358. X                    b2++;
  1359. X# ifdef DEBUG
  1360. X                fprintf (prot, "found seq between %1d and %1d -->",
  1361. X                    (int)(b1-buf), (int)(b2-buf));
  1362. X                { CHAR_TYPE * tmp;
  1363. X                    for (tmp = b1; tmp < b2; tmp++)
  1364. X                        if (IS_PRINTABLE(*tmp))
  1365. X                            fputc (*tmp, prot);
  1366. X                        else
  1367. X                            fputc ('.', prot);
  1368. X                }
  1369. X                fprintf (prot, "<--\n");
  1370. X# endif
  1371. X                /*
  1372. X                 * Should set state to DECIDE; but we don't need it.
  1373. X                 * state will be reset anyway.
  1374. X                 */
  1375. X                /* FALL THROUGH */
  1376. X            case DECIDE:
  1377. X                /*
  1378. X                 * Can we decide what to do with the sequence which
  1379. X                 * we have found? We cannot, if we are at the end of
  1380. X                 * the block, because we need just one more character.
  1381. X                 */
  1382. X                if (b2 >= end) {
  1383. X# ifdef DEBUG
  1384. X                    fprintf (prot, "I cannot decide. Must read a new block.\n");
  1385. X# endif
  1386. X                    (void) append (b1, b2, 0);
  1387. X                    return (TRY);
  1388. X                }
  1389. X# ifdef DEBUG
  1390. X                fprintf (prot, "I can decide.\n");
  1391. X                if (ind_c) {
  1392. X                    if (*b2 == '\0' || *b2 == '\n')
  1393. X                        fprintf (prot, "String is a C string; followed by %s\n",
  1394. X                            *b2 == '\0'?"NUL":"\\n");
  1395. X                }
  1396. X# endif
  1397. X                if (((int)(b2-b1)+saved >= min_str_len) &&
  1398. X                    (!ind_c || (*b2 == '\0' || *b2 == '\n'))) {
  1399. X                    /*
  1400. X                     * String is accepted. Copy it to the output buffer.
  1401. X                     */
  1402. X# ifdef DEBUG
  1403. X                    fprintf (prot, "Accept string.\n");
  1404. X# endif
  1405. X                    (void) append (b1, b2, 1);
  1406. X                } else {
  1407. X                    /*
  1408. X                     * String is refused. Forget any temporarily buffered
  1409. X                     * stuff in output buffer.
  1410. X                     */
  1411. X# ifdef DEBUG
  1412. X                    fprintf (prot, "String refused.\n");
  1413. X# endif
  1414. X                    level = out_buf + num_out_buf;
  1415. X                    saved = 0;
  1416. X                }
  1417. X                state = SEARCH;
  1418. X        }    /* switch */
  1419. X    }    /* for (;b < end; ... */
  1420. X    return (state);
  1421. X}
  1422. X
  1423. Xstrings (name)
  1424. Xchar * name;
  1425. X/*
  1426. X * Find strings in a file or an input stream.
  1427. X * This routine sets the limits to handle a file, either to the
  1428. X * whole file, or to the initialized data only.
  1429. X * In a loop it reads blocks from the file and calls the DFA ('examine').
  1430. X * Examine returns its state, so that it can be reentered at the
  1431. X * right place.
  1432. X */
  1433. X{
  1434. X    register int n, state;
  1435. X    LSEEK_TYPE l, first, last;
  1436. X
  1437. X    if (name == NULL) {
  1438. X        fd = 0;
  1439. X    } else
  1440. X        if ((fd = open (name, O_RDONLY, 0)) == -1) {
  1441. X            perror (name);
  1442. X            return;
  1443. X        }
  1444. X    if (name == NULL || ind_whole == 1) {
  1445. X        first = (LSEEK_TYPE)0;
  1446. X        last = (LSEEK_TYPE)(-1);         /* --> no limit */
  1447. X    } else {
  1448. X# ifdef I_SPECIAL
  1449. X        /*
  1450. X         * Get the limits for reading.
  1451. X         * If the file is not an object, then we look at whole file.
  1452. X         */
  1453. X        get_limits (fd, &first, &last);
  1454. X# ifdef DEBUG
  1455. X        fprintf (prot, "lseek to %ld; last = %ld\n", (long)first, (long)last);
  1456. X# endif
  1457. X        if (lseek (fd, first, 0) != first) {
  1458. X            perror ("lseek");
  1459. X            return;
  1460. X        }
  1461. X# else I_SPECIAL
  1462. X        first = (LSEEK_TYPE)0;
  1463. X        last = (LSEEK_TYPE)(-1);         /* --> no limit */
  1464. X# endif I_SPECIAL
  1465. X    }
  1466. X
  1467. X    cur_file_name = name;
  1468. X    offset = first;
  1469. X    state = SEARCH;
  1470. X    for (;;) {
  1471. X        /*
  1472. X         * Do we really have to read a block ?
  1473. X         * How much should we read? The difficult thing here
  1474. X         * is to watch out not to read beyond the limits of
  1475. X         * initialized data.
  1476. X         */
  1477. X        if (last != (LSEEK_TYPE)(-1)) {
  1478. X            l = last - offset;
  1479. X            if (l <= 0)
  1480. X                break;
  1481. X            if (l > IN_BUF_LEN)
  1482. X                l = IN_BUF_LEN;
  1483. X        } else
  1484. X                l = IN_BUF_LEN;
  1485. X# ifdef DEBUG
  1486. X        fprintf (prot, "reading %1ld chars\n", l);
  1487. X# endif
  1488. X        if ((n = read (fd, buf, (int)l)) <= 0)
  1489. X            break;
  1490. X# ifdef DEBUG
  1491. X        fprintf (prot, "read %1d characters\n", n);
  1492. X        fflush (prot);
  1493. X# endif
  1494. X
  1495. X        state = examine (state, n);
  1496. X
  1497. X        offset += n;
  1498. X    }
  1499. X    if (n == -1)
  1500. X        perror ("read");
  1501. X    /*
  1502. X     * If the piece of the file ended with a string of printable characters,
  1503. X     * we must check whether this string is valid.
  1504. X     * We need not peek at the first character after the strings, as we know
  1505. X     * that it cannot be \0 or \n.
  1506. X     */
  1507. X    if (saved > 0 && !ind_c)
  1508. X        if (saved >= min_str_len)
  1509. X            (void) append (buf, buf, 1);
  1510. X    /*
  1511. X     * We must flush the output buffer.
  1512. X     */
  1513. X    flush_output ();
  1514. X    if (name != 0)
  1515. X        (void)close (fd);
  1516. X}
  1517. X
  1518. X# ifndef FAST_COPY
  1519. Xchar *
  1520. XFAST_COPY (from, to, count)
  1521. Xregister char * from, * to;
  1522. Xregister int count;
  1523. X{
  1524. X    register char * tmp;
  1525. X
  1526. X    tmp = to;
  1527. X    while (count--)
  1528. X        *to++ = *from++;
  1529. X    return (tmp);
  1530. X}
  1531. X# endif FAST_COPY
  1532. END_OF_FILE
  1533. if test 13637 -ne `wc -c <'strings.c'`; then
  1534.     echo shar: \"'strings.c'\" unpacked with wrong size!
  1535. fi
  1536. # end of 'strings.c'
  1537. fi
  1538. if test -f 'strings.h' -a "${1}" != "-c" ; then 
  1539.   echo shar: Will not clobber existing file \"'strings.h'\"
  1540. else
  1541. echo shar: Extracting \"'strings.h'\" \(1170 characters\)
  1542. sed "s/^X//" >'strings.h' <<'END_OF_FILE'
  1543. X/*
  1544. X * Main include file for 'strings'.
  1545. X * Tests Makefile flags and takes appropriate action.
  1546. X * Includes most include files and predefines global defines.
  1547. X *
  1548. X * sccsid : @(#)  strings.h  (v6.3 5/22/89)
  1549. X */
  1550. X
  1551. X# include "config.h"
  1552. X
  1553. X# if defined(DEBUG)
  1554. X#    include <stdio.h>
  1555. X# else
  1556. X#    define stderr    2
  1557. X#    define NULL        0
  1558. X# endif DEBUG
  1559. X
  1560. X# ifdef FCNTL
  1561. X#    if FCNTL == 1
  1562. X#        include <fcntl.h>
  1563. X#    endif
  1564. X#    if FCNTL == 2
  1565. X#        include <sys/fcntl.h>
  1566. X#    endif
  1567. X# else FCNTL
  1568. X#    define O_RDONLY    0
  1569. X# endif FCNTL
  1570. X
  1571. X# ifdef DEBUG
  1572. XFILE * prot;
  1573. X# endif
  1574. X
  1575. X# ifdef I_SPECIAL
  1576. X#    ifdef WHAT_LSEEK
  1577. X#        if WHAT_LSEEK == 1
  1578. X#            define LSEEK_TYPE    long
  1579. X#        endif
  1580. X#        if WHAT_LSEEK == 2
  1581. X#            define LSEEK_TYPE    int
  1582. X#        endif
  1583. X#    endif WHAT_LSEEK
  1584. X
  1585. X#    ifndef LSEEK_TYPE
  1586. X#        include "ERROR : WHAT_LSEEK defined wrongly"
  1587. X#    endif LSEEK_TYPE
  1588. X
  1589. Xextern LSEEK_TYPE lseek (/* int fd; LSEEK_TYPE offset; int whence */);
  1590. X
  1591. X# else I_SPECIAL
  1592. X/*
  1593. X * If I_SPECIAL is not defined we don't need lseek, but we need a type
  1594. X * for offsets.
  1595. X */
  1596. X#    define LSEEK_TYPE    long
  1597. X# endif I_SPECIAL
  1598. X
  1599. X# if THRESHOLD < IN_BUF_LEN
  1600. X#    include "ERROR : THRESHOLD must be >= IN_BUF_LEN"
  1601. X# endif
  1602. X
  1603. Xextern char * malloc ();
  1604. Xextern char * realloc ();
  1605. X
  1606. X# define CHAR_TYPE    char
  1607. END_OF_FILE
  1608. if test 1170 -ne `wc -c <'strings.h'`; then
  1609.     echo shar: \"'strings.h'\" unpacked with wrong size!
  1610. fi
  1611. # end of 'strings.h'
  1612. fi
  1613. if test -f 'strings.txt' -a "${1}" != "-c" ; then 
  1614.   echo shar: Will not clobber existing file \"'strings.txt'\"
  1615. else
  1616. echo shar: Extracting \"'strings.txt'\" \(5006 characters\)
  1617. sed "s/^X//" >'strings.txt' <<'END_OF_FILE'
  1618. XNAME
  1619. X      strings - find and output the printable strings in a file
  1620. X
  1621. XSYNOPSIS
  1622. X     strings [ -option ] [ filename ] ...
  1623. X
  1624. X     option is one of a,-,o,p,t,v,e,c or a number.
  1625. X
  1626. XDESCRIPTION
  1627. X     "strings" looks for sequences of printable characters in a file and outputs
  1628. X     them, if they are longer than "number". Default for "number" is 4.
  1629. X     If "strings" identifies a file as containing an object, it will only scan
  1630. X     the initialized data segment of the object. If you specified either the
  1631. X     "-a" or "-" flags it will scan the whole file.
  1632. X     If there is more than one filename specified, the name of the file
  1633. X     is output before the stuff from that file.
  1634. X     If there is no filename specified "strings" will read from standard input.
  1635. X
  1636. XOPTIONS
  1637. X     "-" or
  1638. X     "-a" examine the entire file for sequences of printable characters. Default
  1639. X          on UNIX (trademark of AT&T) systems is to examine only the segment of
  1640. X          initialized data. On systems where such a segment does not exist, the
  1641. X          options "-a" and "-" do not exist.
  1642. X     "-o" precede each output string by its offset from the beginning of the
  1643. X          file (in decimal).  The number is output with (at least) 7 digits,
  1644. X          filled with blanks. Then follows a blank, then the found string.
  1645. X          If these 7 digits are not sufficent to hold the offset, "strings"
  1646. X          will use 8 digits or as much as necessary (and possible :-).
  1647. X     "number"  only output sequences longer than or as long as "number".
  1648. X          Only decimal values are accepted.
  1649. X     "-p" prefix each output with the name of the input file. This is useful
  1650. X          e.g. if "strings" is used on a list of files and "fgrep" is used to
  1651. X          search for a certain string. When this string is found you will get
  1652. X          the name of the file the string was found in.
  1653. X     "-e" the next argument is interpreted as a filename, even if it starts
  1654. X          with a "-".  Thus "strings -e -a" will try to read from file "-a".
  1655. X     "-t" TAB is considered a printable character.
  1656. X     "-c" output only strings which end with a NUL or LF character. Most strings
  1657. X          in C programs will result in strings like this.
  1658. X     "-v" print information about "strings" version, including the flags
  1659. X          with which it was compiled. This may be uninteresting to the normal
  1660. X          user, but is quite informative when porting to another system.
  1661. X          Nothing else is output, the program exits immediately afterwards.
  1662. X
  1663. X     Options can be specified in a single word. They apply to all files
  1664. X     specified.  It is an error for an option to be specified twice.
  1665. X     The following invocations are correct:
  1666. X
  1667. X          strings -ao12 m1 m2 m3
  1668. X          strings -a -ot -12 m1
  1669. X          strings -a m1 -o m2
  1670. X          strings - -o
  1671. X          strings core -a blabla -o rhabarber -12
  1672. X
  1673. X      The following invocations are incorrect:
  1674. X
  1675. X          strings -a - BBB
  1676. X          strings -aa m
  1677. X          strings -12a14 core
  1678. X
  1679. XAUTHOR
  1680. X      Michael Greim
  1681. X
  1682. X      greim@sbsvax.uucp
  1683. X      greim@sbsvax.informatik.uni-saarland.dbp.de
  1684. X
  1685. XDIAGNOSTICS
  1686. X      Diagnostics are always written to file descriptor 2, i.e. if a file cannot
  1687. X      be opened or malloc runs out of memory.
  1688. X      If the user makes an error when invoking "strings", a table with
  1689. X      the correct syntax will be output.
  1690. X      If the output buffer overflows, the program tries to enlarge it using
  1691. X      realloc. If this fails, it prints a message and exits
  1692. X      immediately.
  1693. X
  1694. XBUGS
  1695. X     "Strings" does not inform the user, whether it has found an object file
  1696. X     or not.
  1697. X
  1698. X     If you have a file which contains a long sequence of printable characters,
  1699. X     e.g. about as long as to become as large as your computers memory size,
  1700. X     "strings" might run out of memory. It will print "REALLOC error" and
  1701. X     exit.
  1702. X
  1703. X     If a file contains a magic number for object files, "strings" thinks
  1704. X     it has found an object file and interpretes the bytes at a certain location
  1705. X     as offsets into the file. This may lead to errors, but "strings"
  1706. X     does not tell the user about it.
  1707. X
  1708. X     The way to identify an object file, or even the concept of initialized
  1709. X     data may vary with systems. When "strings" is compiled one can turn
  1710. X     off this special feature (I_SPECIAL). Consequently the options
  1711. X     "-a" and "-" are no longer valid. Invoke "strings" with an invalid
  1712. X     option to get a list of possible options.
  1713. X
  1714. X     If "strings" is invoked on the standard input it fills up its buffer
  1715. X     before it outputs anything. If you enter a line at a time, it
  1716. X     takes some time before you see the first output.
  1717. X
  1718. X     If "strings" is invoked on the standard input, it does not try to
  1719. X     recognize an object file, but acts as if the flags "-a" or "-"
  1720. X     had been set.
  1721. X
  1722. X     The option "c" will not get all C strings. If you use something like
  1723. X         printf ("Say something\r\n");
  1724. X     and you specify "c" when invoking "strings" you will not get the string,
  1725. X     because it does not end with NUL or LF.
  1726. END_OF_FILE
  1727. if test 5006 -ne `wc -c <'strings.txt'`; then
  1728.     echo shar: \"'strings.txt'\" unpacked with wrong size!
  1729. fi
  1730. # end of 'strings.txt'
  1731. fi
  1732. if test -f 'test_input' -a "${1}" != "-c" ; then 
  1733.   echo shar: Will not clobber existing file \"'test_input'\"
  1734. else
  1735. echo shar: Extracting \"'test_input'\" \(201 characters\)
  1736. sed "s/^X//" >'test_input' <<'END_OF_FILE'
  1737. Xxbtoa Begin
  1738. X<+oue+DGm>@3BZ'F*&OCAfu/:EbTE(F"Rf!BPDN1Ch[cu+Cf>-FCAm$F!*%u$p6*a@3B&uDKKo;C`m
  1739. XOH$@l)hBlbD5Bl7K)F*(i2FE8RKBln#2@3BH+DCo:<@qfX"@q]:k@:OCjEZd&\3%url
  1740. Xxbtoa End N 116 74 E 9d S 27d9 R f6b359b1
  1741. END_OF_FILE
  1742. if test 201 -ne `wc -c <'test_input'`; then
  1743.     echo shar: \"'test_input'\" unpacked with wrong size!
  1744. fi
  1745. # end of 'test_input'
  1746. fi
  1747. if test -f 'tune.h' -a "${1}" != "-c" ; then 
  1748.   echo shar: Will not clobber existing file \"'tune.h'\"
  1749. else
  1750. echo shar: Extracting \"'tune.h'\" \(2077 characters\)
  1751. sed "s/^X//" >'tune.h' <<'END_OF_FILE'
  1752. X/*
  1753. X *
  1754. X * sccsid = @(#)  tune.h  (v6.2 5/17/89)
  1755. X * 
  1756. X * This file contains the flags with which you can tune strings.
  1757. X * Define USE_USER_DEFINES in Makefile to really get them going.
  1758. X */
  1759. X
  1760. X/*
  1761. X * Look in /usr/include, /usr/include/sys, ...
  1762. X * Where are the flags O_RDONLY, O_WRONLY, ... ?
  1763. X * Define FCNTL as
  1764. X * 1 : /usr/include/fcntl.h
  1765. X * 2 : /usr/include/sys/fcntl.h
  1766. X * If they are not defined, then omit FCNTL.
  1767. X * strings will use old flag 0 (read only).
  1768. X *
  1769. X * Examples:
  1770. X * vax BSD43, sun SUN OS  : 1
  1771. X * mx2 SINIX (System III) : 2
  1772. X */
  1773. X# define FCNTL 2
  1774. X
  1775. X/*
  1776. X * We copy sequences of characters with a fast memory copy routine.
  1777. X * On BSD systems this routine is called bcopy. Its usage is :
  1778. X *        bcopy (from, to, count)
  1779. X * On SYS 5 systems this routine is called memcpy. Its usage is :
  1780. X *        memcpy (to, from, count)
  1781. X * Decide what your system uses and define bcopy accordingly.
  1782. X * If you don't define FAST_COPY here, a routine of my own, called
  1783. X * FAST_COPY will be used.
  1784. X */
  1785. X# define FAST_COPY(from,to,count)        bcopy(from,to,count)
  1786. X
  1787. X/*
  1788. X * Take a look at your manual. What does it say about 'lseek' ?
  1789. X * Is it :
  1790. X * 1 : long lseek (int fd, long dist, int whence)
  1791. X * 2 : int lseek (int fd, int dist, int whence)
  1792. X * If it is something else, you will have to change the source. You can
  1793. X * ignore it of course, if int==long on your machine.
  1794. X */
  1795. X# define WHAT_LSEEK    1
  1796. X
  1797. X/*
  1798. X * As a default strings looks at the beginning of a file. If it thinks
  1799. X * it has found an object, it only examines the initialized data in it.
  1800. X * If you want this behaviour define I_SPECIAL. If you always want the
  1801. X * whole file examined, or if you are on a non-UNIX machine where the
  1802. X * identification of object files is different, do not define I_SPECIAL.
  1803. X */
  1804. X# define I_SPECIAL
  1805. X
  1806. X/*
  1807. X * How big should the buffers be?
  1808. X * IN_BUF_LEN  : Length of input buffer for reads.
  1809. X * OUT_BUF_LEN : Maximal size of output buffer.
  1810. X * TRHESHOLD   : Minimal size for writes. If the output buffer grows beyond
  1811. X *               THRESHOLD then it is output.
  1812. X */
  1813. X# define IN_BUF_LEN        1024
  1814. X# define OUT_BUF_LEN    8192
  1815. X# define THRESHOLD        1024
  1816. END_OF_FILE
  1817. if test 2077 -ne `wc -c <'tune.h'`; then
  1818.     echo shar: \"'tune.h'\" unpacked with wrong size!
  1819. fi
  1820. # end of 'tune.h'
  1821. fi
  1822. echo shar: End of archive 1 \(of 1\).
  1823. cp /dev/null ark1isdone
  1824. MISSING=""
  1825. for I in 1 ; do
  1826.     if test ! -f ark${I}isdone ; then
  1827.     MISSING="${MISSING} ${I}"
  1828.     fi
  1829. done
  1830. if test "${MISSING}" = "" ; then
  1831.     echo You have the archive.
  1832.     rm -f ark[1-9]isdone
  1833. else
  1834.     echo You still need to unpack the following archives:
  1835.     echo "        " ${MISSING}
  1836. fi
  1837. ##  End of shell archive.
  1838. exit 0
  1839.  
  1840.  
  1841.